<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"chentianming11.github.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"default"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":{"enable":true,"onlypost":false,"loadingImg":"/uploads/loading.gif"},"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="如果要我们设计一个基于Redis统计页面UV的实现方案，可能的实现方案有什么？大家可能很容易想到的一个方案就是使用Set对象保存每一个访问页面的用户id，因为Set结构天然就支持去重功能，因此使用scard取出的Set集合大小即为页面UV。但是，如果页面UV非常巨大时，使用Set结构存储就会非常浪费空间。Redis提供了HyperLogLog数据结构来解决这类统计问题，既节省内存占用，又能保证统计">
<meta property="og:type" content="article">
<meta property="og:title" content="如何使用Redis实现页面UV统计-HyperLogLog实现详解">
<meta property="og:url" content="https://chentianming11.github.io/posts/1507822429/index.html">
<meta property="og:site_name" content="伍六七">
<meta property="og:description" content="如果要我们设计一个基于Redis统计页面UV的实现方案，可能的实现方案有什么？大家可能很容易想到的一个方案就是使用Set对象保存每一个访问页面的用户id，因为Set结构天然就支持去重功能，因此使用scard取出的Set集合大小即为页面UV。但是，如果页面UV非常巨大时，使用Set结构存储就会非常浪费空间。Redis提供了HyperLogLog数据结构来解决这类统计问题，既节省内存占用，又能保证统计">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://chentianming11.github.io/images/redis/loglog.webp">
<meta property="og:image" content="https://chentianming11.github.io/images/redis/hyperloglog.webp">
<meta property="og:image" content="https://chentianming11.github.io/images/redis/redis-hyperloglog.webp">
<meta property="og:image" content="https://chentianming11.github.io/images/redis/pfadd.webp">
<meta property="article:published_time" content="2020-10-17T04:44:53.000Z">
<meta property="article:modified_time" content="2020-11-01T06:28:57.811Z">
<meta property="article:author" content="陈添明">
<meta property="article:tag" content="redis">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://chentianming11.github.io/images/redis/loglog.webp">

<link rel="canonical" href="https://chentianming11.github.io/posts/1507822429/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>如何使用Redis实现页面UV统计-HyperLogLog实现详解 | 伍六七</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">伍六七</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">一起学Java</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">6</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">3</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">17</span></a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

  <a href="https://github.com/chentianming11" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://chentianming11.github.io/posts/1507822429/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="陈添明">
      <meta itemprop="description" content="一个爱看国漫的程序猿">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="伍六七">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          如何使用Redis实现页面UV统计-HyperLogLog实现详解
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-10-17 12:44:53" itemprop="dateCreated datePublished" datetime="2020-10-17T12:44:53+08:00">2020-10-17</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-11-01 14:28:57" itemprop="dateModified" datetime="2020-11-01T14:28:57+08:00">2020-11-01</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/" itemprop="url" rel="index"><span itemprop="name">数据库</span></a>
                </span>
            </span>

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/posts/1507822429/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/posts/1507822429/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>2.1k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>5 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>如果要我们设计一个基于<code>Redis</code>统计页面<code>UV</code>的实现方案，可能的实现方案有什么？<br>大家可能很容易想到的一个方案就是使用<code>Set</code>对象保存每一个访问页面的<code>用户id</code>，因为<code>Set</code>结构天然就支持去重功能，因此使用<code>scard</code>取出的<code>Set</code>集合大小即为页面<code>UV</code>。但是，如果页面<code>UV</code>非常巨大时，使用<code>Set</code>结构存储就会非常浪费空间。<br><strong><code>Redis</code>提供了<code>HyperLogLog</code>数据结构来解决这类统计问题，既节省内存占用，又能保证统计结果在可接受的误差之内</strong>。</p>
<a id="more"></a>

<h2 id="Redis中的HyperLogLog使用"><a href="#Redis中的HyperLogLog使用" class="headerlink" title="Redis中的HyperLogLog使用"></a>Redis中的HyperLogLog使用</h2><p><code>Redis</code>中的<code>HyperLogLog</code>提供了两个指令<code>pfadd</code>和<code>pfcount</code>。<code>pfadd</code>用于增加计数，<code>pfcount</code>用于获取计数。针对上面的统计页面<code>UV</code>的场景，当用户访问页面时，就使用<code>pfadd</code>指令将<code>用户id</code>添加到<code>HyperLogLog</code>中，最后执行<code>pfcount</code>就能获取到页面<code>UV</code>。</p>
<h2 id="HyperLogLog算法介绍"><a href="#HyperLogLog算法介绍" class="headerlink" title="HyperLogLog算法介绍"></a>HyperLogLog算法介绍</h2><p>实际上，<strong><code>HyperLogLog</code>是一种够提供不精确的去重计的算法</strong>。存在以下的特点：</p>
<ol>
<li>能够使用极少的内存来统计巨量的数据，在<code>Redis</code>中实现的<code>HyperLogLog</code>，只需要12K内存就能统计<code>2^64</code>个数据。</li>
<li>计数存在一定的误差，误差率整体较低。标准误差为<code>0.81%</code>。</li>
<li>误差可以被设置辅助计算因子进行降低。</li>
</ol>
<h3 id="伯努利试验"><a href="#伯努利试验" class="headerlink" title="伯努利试验"></a>伯努利试验</h3><blockquote>
<p>伯努利试验是数学概率论中的一部分内容，它的典故来源于抛硬币。</p>
</blockquote>
<p>硬币拥有正反两面，每次的上抛至落下，出现正反面的概率都是<code>1/2</code>。第一次出现正面的概率是<code>1/2</code>，连续2次出现正面的概率就是<code>1/4</code>, 连续出现<code>K</code>次正面的概率就是<code>2^(-k)</code>。假设一直抛硬币，直到它出现正面为止，我们记录为一次完整的试验，中间可能抛了一次就出现了正面，也可能抛了4次才出现正面。无论抛了多少次，只要出现了正面，就记录为一次试验。这个试验就是伯努利试验。</p>
<p>那么对于<code>n</code>次的伯努利试验，假设每次伯努利试验所经历了的抛掷次数为<code>k</code>。那么第一次伯努利试验，次数设为<code>k1</code>，以此类推，第<code>n</code>次对应的是<code>kn</code>。其中，对于这<code>n</code>次伯努利试验中，必然会有一个最大的抛掷次数<code>k_max</code>。</p>
<p>最终结合极大似然估算的方法，发现在<code>n</code>和<code>k_max</code>中存在估算关联：<code>n * 2^(-k_max)=1</code>，即<code>n = 2^(k_max)</code>。</p>
<h3 id="估算优化"><a href="#估算优化" class="headerlink" title="估算优化"></a>估算优化</h3><p>我们只进行<code>n</code>次伯努利试验称为一轮实验。当<code>n</code>足够大的时候，估算的误差率会相对减少，但仍然不够小。<br>但是如果我们进行更多轮次实验，然后再取每轮的 <code>k_max</code>的平均数。最终再估算出 <code>n</code>，这样子的误差就会相对减少很多。下面是LogLog的估算公式：<br><img data-src="https://chentianming11.github.io/images/redis/loglog.webp" alt="loglog"></p>
<p>上面公式的<code>DVLL</code>对应的就是<code>n</code>，<code>constant</code>是修正因子，它的具体值是不定的，可以根据实际情况而分支设置。<code>m</code>代表的是试验的轮数。头上有一横的<code>R</code>就是平均数：<code>(k_max_1 + ... + k_max_m)/m</code>。</p>
<p>这种通过增加试验轮次，再取<code>k_max</code>平均数的算法优化就是LogLog的做法。而 <code>HyperLogLog</code>和<code>LogLog</code>的区别就是，它采用的不是平均数，而是调和平均数。<em>调和平均数比平均数的好处就是不容易受到大的数值的影响</em>。下面举个例子：<br><img data-src="https://chentianming11.github.io/images/redis/hyperloglog.webp" alt="hyperloglog"></p>
<h3 id="程序实现"><a href="#程序实现" class="headerlink" title="程序实现"></a>程序实现</h3><p>通过上面的内容我们已经知道，在抛硬币的例子中，<strong>可以通过一次伯努利试验中出现的<code>k_max</code>来估算<code>n</code></strong>。</p>
<h4 id="将数据转换为比特串"><a href="#将数据转换为比特串" class="headerlink" title="将数据转换为比特串"></a>将数据转换为比特串</h4><p>通过<code>hash</code>函数，将数据转换为<strong>比特串</strong>，例如输入<code>5</code>，可以转换为为：<code>101</code>。这么做的目的是和抛硬币对上，在比特串中，<code>0</code>代表反面，<code>1</code>代表正面。如果一个数据最终被转化了<code>10010000</code>，那么从右往左看，我们可以认为，首次出现<code>1</code>的时候，就是正面。基于上面的估算结论，我们可以根据存入数据中，转化后的出现了<code>1</code>的最大的位置<code>k_max</code>来估算存入了多少数据，即<code>n = 2^(k_max)</code>。</p>
<h4 id="分桶"><a href="#分桶" class="headerlink" title="分桶"></a>分桶</h4><p>分桶就是分多少轮。具体到程序实现上，就是将输入数据<code>hash</code>转换为<strong>比特串</strong>的时候，先确定桶号，然后再将第一个出现<code>1</code>的个位数值设置到该桶中。</p>
<h2 id="Redis中的HyperLogLog实现"><a href="#Redis中的HyperLogLog实现" class="headerlink" title="Redis中的HyperLogLog实现"></a>Redis中的HyperLogLog实现</h2><p>在<code>Redis</code>中的<code>HyperLogLog</code>中，共分为<code>2^14</code>个桶，每个桶有<code>6</code>个<code>bit</code>，占用内存为=<code>2^14*6/8/1024=12K</code>。<br><img data-src="https://chentianming11.github.io/images/redis/redis-hyperloglog.webp" alt="redis-hyperloglog"></p>
<p>当我们执行命令<code>pfadd key value</code>时，首先会通过<code>hash</code>函数将<code>value</code>转换为<code>64</code>位比特串。其中，前14位用来确定分桶(刚好有<code>2^14</code>个桶)，后<code>50</code>位用来获取第一个出现<code>1</code>的位数(从右向左)，因为最大为<code>50</code>，因此使用<code>6</code>个<code>bit</code>完全可以表示。<br><img data-src="https://chentianming11.github.io/images/redis/pfadd.webp" alt="pfadd"></p>
<p>不同的<code>value</code>，会被设置到不同桶中去，如果出现了在同一个桶的，但是后面第一个出现<code>1</code>的位数不同。那么比较这个桶新的值是否比原来的值大，如果大于，则替换。否则，保持不变。</p>
<p>最终，<code>2^14</code>个桶都保存了出现<code>1</code>的最大值<code>k_max</code>，此时调用<code>pfcount</code>时，按照前面介绍的估算方式，便可以计算出<code>key</code>的设置了多少次<code>valu</code>，也就是统计值，即<code>2^14*2^(k_max平均)</code>。</p>
<h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><ol>
<li><a href="https://juejin.im/post/6844903785744056333" target="_blank" rel="noopener">https://juejin.im/post/6844903785744056333</a></li>
<li><a href="https://juejin.im/post/6844903667712294919" target="_blank" rel="noopener">https://juejin.im/post/6844903667712294919</a></li>
</ol>
<blockquote>
<p>原创不易，觉得文章写得不错的小伙伴，点个赞👍 鼓励一下吧~</p>
</blockquote>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/redis/" rel="tag"># redis</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/posts/2583560655/" rel="prev" title="一文读懂Redis常见对象类型的底层数据结构">
      <i class="fa fa-chevron-left"></i> 一文读懂Redis常见对象类型的底层数据结构
    </a></div>
      <div class="post-nav-item">
    <a href="/posts/4169530895/" rel="next" title="深入理解Redis持久化机制-RDB、AOF实现详解">
      深入理解Redis持久化机制-RDB、AOF实现详解 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Redis中的HyperLogLog使用"><span class="nav-number">1.</span> <span class="nav-text">Redis中的HyperLogLog使用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#HyperLogLog算法介绍"><span class="nav-number">2.</span> <span class="nav-text">HyperLogLog算法介绍</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#伯努利试验"><span class="nav-number">2.1.</span> <span class="nav-text">伯努利试验</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#估算优化"><span class="nav-number">2.2.</span> <span class="nav-text">估算优化</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#程序实现"><span class="nav-number">2.3.</span> <span class="nav-text">程序实现</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#将数据转换为比特串"><span class="nav-number">2.3.1.</span> <span class="nav-text">将数据转换为比特串</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#分桶"><span class="nav-number">2.3.2.</span> <span class="nav-text">分桶</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Redis中的HyperLogLog实现"><span class="nav-number">3.</span> <span class="nav-text">Redis中的HyperLogLog实现</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#参考"><span class="nav-number">4.</span> <span class="nav-text">参考</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="陈添明"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">陈添明</p>
  <div class="site-description" itemprop="description">一个爱看国漫的程序猿</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">17</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">3</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">陈添明</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">156k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">6:30</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script size="300" alpha="0.6" zIndex="-1" src="//cdn.jsdelivr.net/gh/theme-next/theme-next-canvas-ribbon@1/canvas-ribbon.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/theme-next/theme-next-pjax@0/pjax.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/lozad@1/dist/lozad.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>

  <script>
var pjax = new Pjax({
  selectors: [
    'head title',
    '#page-configurations',
    '.content-wrap',
    '.post-toc-wrap',
    '.languages',
    '#pjax'
  ],
  switches: {
    '.post-toc-wrap': Pjax.switches.innerHTML
  },
  analytics: false,
  cacheBust: false,
  scrollTo : !CONFIG.bookmark.enable
});

window.addEventListener('pjax:success', () => {
  document.querySelectorAll('script[data-pjax], script#page-configurations, #pjax script').forEach(element => {
    var code = element.text || element.textContent || element.innerHTML || '';
    var parent = element.parentNode;
    parent.removeChild(element);
    var script = document.createElement('script');
    if (element.id) {
      script.id = element.id;
    }
    if (element.className) {
      script.className = element.className;
    }
    if (element.type) {
      script.type = element.type;
    }
    if (element.src) {
      script.src = element.src;
      // Force synchronous loading of peripheral JS.
      script.async = false;
    }
    if (element.dataset.pjax !== undefined) {
      script.dataset.pjax = '';
    }
    if (code !== '') {
      script.appendChild(document.createTextNode(code));
    }
    parent.appendChild(script);
  });
  NexT.boot.refresh();
  // Define Motion Sequence & Bootstrap Motion.
  if (CONFIG.motion.enable) {
    NexT.motion.integrator
      .init()
      .add(NexT.motion.middleWares.subMenu)
      .add(NexT.motion.middleWares.postList)
      .bootstrap();
  }
  NexT.utils.updateSidebarPosition();
});
</script>




  




  
<script src="/js/local-search.js"></script>













    <div id="pjax">
  

  
  <script src="//cdn.jsdelivr.net/npm/quicklink@1/dist/quicklink.umd.js"></script>
  <script>
      window.addEventListener('load', () => {
      quicklink({
        timeout : 3000,
        priority: true,
        ignores : [uri => uri.includes('#'),uri => uri === 'https://chentianming11.github.io/posts/1507822429/',]
      });
      });
  </script>


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : true,
      appId      : 'SoPxUkme2aynTULaNuIc5TIq-gzGzoHsz',
      appKey     : '4TDP7SMCbgDKTOGGUtpIeA0H',
      placeholder: "留下点足迹吧~",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : '' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

    </div>
</body>
</html>
